<template>
    <div class="practical-activity-container">
        <div class="content-container">
            <div class="section-title"></div>
            <div class="notification-bar">
                <span class="notification-icon"></span>
                <span class="notification-text">{{ activeType }}</span>
            </div>

            <div class="activity-grid">
                <div class="activity-row">
                    <div v-for="(activity, index) in activities.slice(0, 4)" :key="'row1-' + index"
                        class="activity-card" :class="getCardColorClass(index)">
                        <div class="activity-time"></div>
                        <div class="activity-title">
                            <label class="card-sub-item-title">讲座题目：</label>
                            <span>{{ activity.meetingName }}</span>
                        </div>
                        <div class="activity-title">
                            <label class="card-sub-item-title">讲座状态：</label>
                            <span>{{ activity.meetingStatus }}</span>
                        </div>
                        <div class="activity-title">
                            <label class="card-sub-item-title">讲座地址：</label>
                            <span>{{ activity.roomName }}</span>
                        </div>
                        <div class="activity-title">
                            <label class="card-sub-item-title">讲座时间：</label>
                            <span>{{ activity.startDate }} - {{ activity.endDate }}</span>
                        </div>
                        <div class="activity-title">
                            <label class="card-sub-item-title">主讲人：</label>
                            <span>{{ activity.userName }} </span>
                        </div>
                    </div>
                </div>

                <div class="navigation-controls" v-if="pageQuery.total > pageQuery.pageSize">
                    <button @click="handlePrev" class="nav-button prev"
                        v-if="pageQuery.pageNum > 1"><span>&lt;</span></button>
                    <button @click="handleNext" class="nav-button next"
                        v-if="pageQuery.pageNum < (pageQuery.total / pageQuery.pageSize)"><span>&gt;</span></button>
                </div>

                <!-- <div class="navigation-controls" >
                    <button @click="handlePrev" class="nav-button prev" ><span>&lt;</span></button>
                    <button @click="handleNext" class="nav-button next" ><span>&gt;</span></button>
                </div> -->

                <div class="activity-row">
                    <div v-for="(activity, index) in activities.slice(4, 8)" :key="'row2-' + index"
                        class="activity-card" :class="getCardColorClass(index)">
                        <div class="activity-time"></div>
                        <div class="activity-title">
                            <label class="card-sub-item-title">讲座题目：</label>
                            <span>{{ activity.meetingName }}</span>
                        </div>
                        <div class="activity-title">
                            <label class="card-sub-item-title">讲座状态：</label>
                            <span>{{ activity.meetingStatus }}</span>
                        </div>
                        <div class="activity-title">
                            <label class="card-sub-item-title">讲座地址：</label>
                            <span>{{ activity.roomName }}</span>
                        </div>
                        <div class="activity-title">
                            <label class="card-sub-item-title">讲座时间：</label>
                            <span>{{ activity.startDate }} - {{ activity.endDate }}</span>
                        </div>
                        <div class="activity-title">
                            <label class="card-sub-item-title">主讲人：</label>
                            <span>{{ activity.userName }} </span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup name="PracticalActivity">
import { getInnovationList } from "@/api/home/home";

const pageQuery = ref({
    pageNum: 1,
    pageSize: 8,
    total: 0,
});
const activities = ref([]);

const activeType = ref("");

function getList() {
    getInnovationList(pageQuery.value).then(response => {
        if (response.code != 200) {
            return;
        }
        // response={
        //     "total": 3,
        //     "pageNum": 1,
        //     "pageSize": 3,
        //     "rows": [
        //         {
        //             "id": 15222,
        //             "userName": "杨来科",
        //             "meetingName": "课程讨论",
        //             "roomName": "理科大楼A914",
        //             "meetingStatus": "未开始",
        //             "startDate": "13:30",
        //             "endDate": "15:30",
        //             "bookTime": "15:59",
        //             "insertTime": "10:20"
        //         },
        //         {
        //             "id": 15569,
        //             "userName": "李亚敏",
        //             "meetingName": "研讨",
        //             "roomName": "理科大楼A302",
        //             "meetingStatus": "未开始",
        //             "startDate": "13:30",
        //             "endDate": "16:30",
        //             "bookTime": "13:47",
        //             "insertTime": "13:05"
        //         },
        //         {
        //             "id": 15571,
        //             "userName": "钟琰",
        //             "meetingName": "讨论班",
        //             "roomName": "理科大楼A1714",
        //             "meetingStatus": "未开始",
        //             "startDate": "15:45",
        //             "endDate": "17:00",
        //             "bookTime": "13:27",
        //             "insertTime": "13:05"
        //         },
        //         {
        //             "id": 15569,
        //             "userName": "李亚敏",
        //             "meetingName": "研讨",
        //             "roomName": "理科大楼A302",
        //             "meetingStatus": "未开始",
        //             "startDate": "13:30",
        //             "endDate": "16:30",
        //             "bookTime": "13:47",
        //             "insertTime": "13:05"
        //         },
        //         {
        //             "id": 15571,
        //             "userName": "钟琰",
        //             "meetingName": "讨论班",
        //             "roomName": "理科大楼A1714",
        //             "meetingStatus": "未开始",
        //             "startDate": "15:45",
        //             "endDate": "17:00",
        //             "bookTime": "13:27",
        //             "insertTime": "13:05"
        //         },
        //         {
        //             "id": 15569,
        //             "userName": "李亚敏",
        //             "meetingName": "研讨",
        //             "roomName": "理科大楼A302",
        //             "meetingStatus": "未开始",
        //             "startDate": "13:30",
        //             "endDate": "16:30",
        //             "bookTime": "13:47",
        //             "insertTime": "13:05"
        //         },
        //         {
        //             "id": 15571,
        //             "userName": "钟琰",
        //             "meetingName": "讨论班",
        //             "roomName": "理科大楼A1714",
        //             "meetingStatus": "未开始",
        //             "startDate": "15:45",
        //             "endDate": "17:00",
        //             "bookTime": "13:27",
        //             "insertTime": "13:05"
        //         }
        //     ],
        //     "code": 200,
        //     "msg": "未开始的活动有3个；"
        // }
        activities.value = response.rows;
        activeType.value = response.msg;

        // pageQuery.value.pageNum = response.pageNum;
        // pageQuery.value.pageSize = response.pageSize;
        pageQuery.value.total = response.total;
    });
}

function handlePrev() {
    if (pageQuery.value.pageNum > 1) {
        pageQuery.value.pageNum--;
        getList();
    }
}
function handleNext() {
    if (pageQuery.value.pageNum < Math.ceil(pageQuery.value.total / pageQuery.value.pageSize)) {
        pageQuery.value.pageNum++;
        getList();
    }
}

function getCardColorClass(index) {
    const colors = ['green', 'blue', 'green', 'blue'];
    return colors[index % colors.length];
}
getList();
</script>

<style scoped>
.practical-activity-container {

    min-width: 100vw;
    min-height: 100vh;
    /* background-image: url('@/assets/home/header/bg.png'); */
    background-repeat: no-repeat;
    background-position: center;
    background-size: cover;
    /* 拉伸填充整个容器 */
}

.notification-bar {
    padding: 10px 0 10px 9%;
    /* 移除左右padding */
    display: flex;
    align-items: center;
    margin-bottom: 20px;
}

.notification-icon {
    background-image: url("@/assets/home/notification.png");
    margin-right: 10px;
    height: 18px;
    width: 18px;
    background-size: cover;
}

.content-container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 20px;
}

.section-title {
    background-image: url("@/assets/home/practicalactivity-title.png");
    margin: 20px auto;
    /* 修改为居中 */
    height: 50px;
    width: 240px;
    background-size: contain;
    /* 修改为contain以确保图片完整显示 */
    background-repeat: no-repeat;
    /* 确保图片不重复 */
    background-position: center;
    /* 确保图片居中 */
}

.section-title::after {
    content: "";
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 100px;
    height: 3px;
}

.content-wrapper {
  flex: 1;
  overflow-y: hidden;
  padding: 5px 0 60px;
  height: calc(100vh - 130px);
  box-sizing: border-box;
}

.activity-grid {
    position: relative;
    margin: 40px auto 0 9%;
}

.activity-row {
    display: flex;
    justify-content: start;
    margin-bottom: 20px;
}

.activity-card {
    width: 20%;
    background-color: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.activity-card-green {
    border-top: 5px solid #98c7b5;
}

.activity-card-blue {
    border-top: 5px solid #54c0e7;
}

.activity-time {
    background-image: url("@/assets/home/clock-icon.png");
    background-repeat: no-repeat;
    background-position: 10px left;
    background-size: 60px;
    background-color: inherit;
    color: #fff;
    padding: 8px 15px;
    font-weight: bold;
    text-align: left;
    padding-left: 40px;
    min-height: 35px;
}

.activity-card.green .activity-time {
    background-color: #99c7b5;
}

.activity-card.blue .activity-time {
    background-color: #4cc2ea;
}

.activity-card.blue {
    margin: auto 50px;
}


.activity-title {
    padding: 8px 15px;
    border-bottom: 1px solid #f0f0f0;
    font-size: 14px;
}

.card-sub-item-title {
    color: #2473cc;
}

.activity-title {
    font-weight: bold;
}


.activity-title span {
    color: #666;
}

.navigation-controls {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    transform: translateY(-50%);
    display: flex;
    justify-content: space-between;
    pointer-events: none;
}

/* 当只有next按钮时 */
.navigation-controls:has(.next:only-child) {
    justify-content: flex-end;
}

/* 当只有prev按钮时 */
.navigation-controls:has(.prev:only-child) {
    justify-content: flex-start;
}


.nav-button {
    width: 16px;
    height: 50px;
    border-radius: 8%;
    background-color: rgba(0, 0, 0, 0.3);
    color: #fff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    pointer-events: auto;
}

.nav-button:hover {
    background-color: rgba(0, 0, 0, 0.7);
}

.nav-button.prev {
    margin-left: -2.5%;
}

.nav-button.next {
    margin-right: 7%;
}

@media (max-height: 1080px) and (max-width: 1920px) {
    .section-title {
        height: 40px;
        margin: 10px auto;
    }


    .activity-section {
        padding-top: 5px;
    }

    .content-wrapper {
        padding: 0px 0 60px;
    }

    .content-container {
        padding: 0;
    }

    .content-container {
        max-width: 1500px;
    }

    .carousel-container {
        padding: 0 20px;
    }

    .nav-button.next {
        margin-right: 7%;
    }

    .content-container {
        max-width: 1600px;
        margin: 0 auto;
        padding: 4px;
    }

    .section-title {
        height: 40px;
        margin: 10px auto;
    }

    .activity-title {
        padding: 5px 14px;
        border-bottom: 1px solid #f0f0f0;
        font-size: 15px;
    }
}


@media (max-height: 840px) {
    .nav-button.next {
        margin-right: 7%;
    }

    .notification-bar {
        font-size: 16px;
        margin-bottom: 0;
    }

    .content-container {
        max-width: 1600px;
        margin: 0 auto;
        padding: 4px;
    }

    .content-wrapper {
        padding: 5px 0 60px;
    }

    .section-title {
        height: 40px;
        margin: 20px auto;
    }

    .activity-title {
        padding: 5px 14px;
        border-bottom: 1px solid #f0f0f0;
        font-size: 12px;
    }

}

@media (max-height: 790px) {
    .section-title {
        height: 40px;
        margin: 8px auto;
    }

    .notification-bar {
        font-size: 13px;
    }

    .activity-grid {
        margin: 20px auto 0 9%;
    }

    .activity-row {
        margin-bottom: 15px;
    }

    .activity-card {
        width: 20%;
    }

    .activity-time {
        min-height: 30px;
        background-size: 50px;
    }

    .activity-title {
        padding: 4px 12px;
        font-size: 11px;
    }

    .nav-button {
        height: 40px;
    }

    .notification-bar {
        padding: 5px 0 5px 9%;
        margin-bottom: 10px;
    }

    .content-container {
        padding: 2px;
    }

    .content-wrapper {
        padding: 5px 0 60px;
    }
}

@media (max-height: 630px) {
    .section-title {
        height: 30px;
        margin: 5px auto;
        width: 200px;
    }

    .activity-grid {
        margin: 10px auto 0 9%;
    }

    .activity-row {
        margin-bottom: 10px;
    }

    .activity-card {
        width: 20%;
        box-shadow: 0 1px 5px rgba(0, 0, 0, 0.1);
    }

    .activity-time {
        min-height: 25px;
        background-size: 40px;
        padding: 5px 12px;
        padding-left: 35px;
    }

    .activity-title {
        padding: 3px 10px;
        font-size: 10px;
        line-height: 1.2;
    }

    .nav-button {
        height: 35px;
        width: 14px;
    }

    .notification-bar {
        padding: 3px 0 3px 9%;
        margin-bottom: 8px;
    }

    .notification-icon {
        height: 15px;
        width: 15px;
    }

    .content-container {
        padding: 1px;
    }

    .activity-card.blue {
        margin: auto 30px;
    }
}

@media (max-width: 1400px) {
    .nav-button.next {
        margin-right: 9%;
    }
}
</style>